#pragma once

#include "../libs/httplib.h"
#include "../libs/easylog.h"
#include "../util.hpp"
#include "../controllers/recordcontroller.hpp"

namespace pharmacy_server
{
    struct RecordBusiness
    {
        static void query_sales_records(const httplib::Request& req, httplib::Response& rsp)
        {
            try
            {
                easylog::debug("queryRecords body: {}", req.body);

                Json::Value root = json_util::deserialize(req.body);
                auto medicine_name = root["medicine_name"].asString();
                auto username = root["username"].asString();
                auto start_date = root["start_date"].asString();
                auto end_date = root["end_date"].asString();

                Result result = RecordController::instance().query_sales_records(medicine_name, username, start_date, end_date);
                rsp.set_content(result.serialize(), "application/json");
            }
            catch (const std::exception& e)
            {
                easylog::error("queryRecords business error: {}", e.what());
            }
        }
    };
}